<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>距离元旦还有:<span></span></h1>
    <script>
        function setdom(params){
        let span= document.querySelector('span')
        let year = new Date().getFullYear()+1
        let newyear=year+'-01-01 0:0:0'
        // 计算差值 毫秒
        let poor = new Date(newyear)- new Date()
        //console.log(poor);
        //天
        let day=(Math.floor(poor/1000/60/60/24)+'').padStart(2,'0')
        //时 
        let hh =(Math.floor(poor/1000/60/60%24)+'').padStart(2,'0')
        //分
        let mm=(Math.floor(poor/1000/60%60)+'').padStart(2,'0')
        // 秒
        let ss=(Math.floor(poor/1000%60)+'').padStart(2,'0')
        
        if(poor>0){
        span.innerHTML=`${day}天${hh}时${mm}分${ss}秒`
        }else{
        span.innerHTML=`新年快乐`
        clearInterval(strpor)
                }
        }
        setdom()
        let strpor =setInterval(setdom,1000)


            </script>
        </body>
</html>